package com.v1.video.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.v1.video.R;

public class CustomAlertDialog {	
	private Dialog mDialog;
	
	private Context mCxt;
	
	private String mTitle="提示";
	private String mMsg="系统消息";
	private String mOkTitle="确定";
	private String mCancelTitle="取消";
	private OnClickListener mOkListener;
	private OnClickListener mCancelListener;
	
	private TextView mTitleTxt;
	private TextView mMsgTxt;
	private TextView mCancelTxt;
	private TextView mOkTxt;
	private View mOkLine;
	
	private CustomAlertDialog(Context cxt){
		this.mCxt = cxt;
		mDialog = new Dialog(mCxt, R.style.dialog_custom);
		mDialog.setContentView(R.layout.custom_alert_dialog_lay);
		mDialog.setCancelable(false);
		mDialog.setCanceledOnTouchOutside(false);
		mTitleTxt = (TextView) mDialog.findViewById(R.id.titleTxt);
		mMsgTxt = (TextView) mDialog.findViewById(R.id.msgTxt);
		mCancelTxt = (TextView) mDialog.findViewById(R.id.cancelTxt);
		mOkTxt = (TextView) mDialog.findViewById(R.id.okTxt);
		mOkLine=(View) mDialog.findViewById(R.id.okline);
		this.mTitleTxt.setText(this.mTitle);
		this.mMsgTxt.setText(this.mMsg);
		this.mOkTxt.setText(mOkTitle);
		this.mCancelTxt.setText(mCancelTitle);
		this.mCancelTxt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.dismiss();
			}
		});
	}
	
	public static CustomAlertDialog builder(Context cxt){
		return new CustomAlertDialog(cxt);
	}
	
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public CustomAlertDialog setTitle(String title) {
		if (!TextUtils.isEmpty(title)) {
			this.mTitleTxt.setText(title);
		}
		return this;
	}
	
	/**
	 * 设置消息内容
	 * @param msg
	 * @return
	 */
	public CustomAlertDialog setMsg(String msg) {
		if (!TextUtils.isEmpty(msg)) {
			this.mMsgTxt.setText(msg);
		}
		return this;
	}
	
	/**
	 * 设置确认按钮文本
	 * @param okTitle
	 * @return
	 */
	public CustomAlertDialog setOKTitle(String okTitle){
		if(!TextUtils.isEmpty(okTitle)){
			this.mOkTxt.setText(okTitle);
			this.mOkLine.setVisibility(View.VISIBLE);
			this.mOkTxt.setVisibility(View.VISIBLE);
		}
		return this;
	}
	
	/**
	 * 设置取消按钮文本
	 * @param cancelTitle
	 * @return
	 */
	public CustomAlertDialog setCancelTitle(String cancelTitle){
		if(!TextUtils.isEmpty(cancelTitle)){
			this.mCancelTxt.setText(cancelTitle);
		}
		return this;
	}
	
	/**
	 * 设置确认事件
	 * @param okListener
	 * @return
	 */
	public CustomAlertDialog setOkListener( final OnClickListener okListener){
		mOkLine.setVisibility(View.VISIBLE);
		mOkTxt.setVisibility(View.VISIBLE);
		mOkTxt.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				if(okListener!=null){
					okListener.onClick(arg0);
				}
				mDialog.dismiss();
			}});
		return this;
	}
	
	/**
	 * 显示
	 */
	public void show(){
		if(this.mDialog!=null)
			this.mDialog.show();
	}
}
